﻿using AbpEntityFrameworkcore.DbContext;
using AbpToDomain.EntityInfo;
using Microsoft.EntityFrameworkCore;

namespace AbpApplication
{
   public  class QueryDynamic
    {
        private readonly MyDbContext context;
     

        public QueryDynamic(MyDbContext context)
        {
            this.context = context;
        }


        public List<lognote> QueryDynameicView_View_Lognote(string?Type,DateTime? StartTime,DateTime? EndTime,string? Note,
            string? User, string? Definition, string? MaterialCode, 
            string? MaterialName, string? Batch, string? Size, string? OrderNo, string? BoxCode,
            string? WarehouseLineCode)
        {
            IQueryable<lognote> view_lognote= context.lognotes.OrderByDescending(x => x.DateTime); 
            if (!string.IsNullOrEmpty(Type))
            {
                view_lognote = view_lognote.Where(x => x.Type.Contains(Type));
            }
            if (!string.IsNullOrEmpty(Note))
            {
                view_lognote = view_lognote.Where(x => x.Note.Contains(Note));
            }
            if (!string.IsNullOrEmpty(User))
            {
                view_lognote = view_lognote.Where(x => x.User.Contains(User));
            }
            if (!string.IsNullOrEmpty(Definition))
            {
                view_lognote = view_lognote.Where(x => x.Definition.Contains(Definition));
            }
            if (!string.IsNullOrEmpty(MaterialCode))
            {
                view_lognote = view_lognote.Where(x => x.MaterialCode.Contains(MaterialCode));
            }
            if (!string.IsNullOrEmpty(MaterialName))
            {
                view_lognote = view_lognote.Where(x => x.MaterialName.Contains(MaterialName));
            }
            if (!string.IsNullOrEmpty(Batch))
            {
                view_lognote = view_lognote.Where(x => x.Batch.Contains(Batch));
            }
            if (!string.IsNullOrEmpty(Size))
            {
                view_lognote = view_lognote.Where(x => x.Size.Contains(Size));
            }
            if (!string.IsNullOrEmpty(OrderNo))
            {
                view_lognote = view_lognote.Where(x => x.OrderNo.Contains(OrderNo));
            }
            if (!string.IsNullOrEmpty(BoxCode))
            {
                view_lognote = view_lognote.Where(x => x.BoxCode.Contains(BoxCode));
            }
            if (!string.IsNullOrEmpty(WarehouseLineCode))
            {
                view_lognote = view_lognote.Where(x => x.WarehouseLineCode.Contains(WarehouseLineCode));
            }
            if(!string.IsNullOrEmpty(StartTime.ToString())&& !string.IsNullOrEmpty(EndTime.ToString()))
            {
                view_lognote = view_lognote.Where(x => x.DateTime>=StartTime&&x.DateTime<=EndTime.Value.AddDays(1));
            }

            return view_lognote.ToList();
        }



    }
}
